Repository navigation
fix(id-web): keep marks spanning inline HTML atoms as one span on save (#1412) - #1505
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 10 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 93cf8b887c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for atom in &children[split..] { | ||
| atom.detach(); | ||
| tail.append(atom); |
There was a problem hiding this comment.
Preserve HTML boundaries between independent marked spans
When two separate marked spans surround an opening HTML tag, adopting that tag changes their nesting and can change rendered formatting. For example, *a*<span style="font-style: normal">*b*</span> now saves as *a<span style="font-style: normal">b*</span>, leaving the closing HTML tag outside the emphasis wrapper. Previously the inner <em> made b italic; after saving, the span's explicit normal style overrides the enclosing emphasis and b is no longer italic. Matching marks on either side alone does not establish that the intervening HTML belongs inside the mark; preserve boundaries for HTML elements that extend beyond the marked span.
Useful? React with 👍 / 👎.
| let children: Vec<&'a AstNode<'a>> = parent.children().collect(); | ||
| let mut split = children.len(); |
There was a problem hiding this comment.
Inspect only trailing siblings instead of collecting every child
For a long paragraph containing alternating marked and unmarked runs, such as repeated *a* b , every marked run now collects all previously appended siblings even though there are no HTML atoms to adopt. Since append_inline_child calls this helper for every marked chain, a paragraph with n such runs incurs Θ(n²) sibling visits and repeated allocations, whereas the previous tail insertion only inspected the last child. This introduces quadratic work on ordinary Markdown saves through convert_doc_to_bytes. Walk backward from last_child() through only the trailing HTML atoms, returning immediately when the last child is not HTML.
Useful? React with 👍 / 👎.
Fixes #1412.
Problem
In
pkgs/id's web markdown codec, a mark spanning anhtml_inlineatom fragmented on save:[a <b>x</b> c](/y)saved as[a ](/y)<b>[x](/y)</b>[ c](/y), and emphasis forms leaked entities at the seams. The parse direction emitshtml_inlineatoms markless by design, so the save direction saw marked run → bare atom → marked run, and the atom landing as a sibling severed the tail mark wrapper.Fix
append_inline_child(save side,pkgs/id/src/web/markdown.rs): before inserting a peeled mark chain,adopt_trailing_html_atomsmoves any trailinghtml_inlineatoms into the tail mark wrapper when the incoming chain shares that wrapper's mark — recursing along the chain's shared marks (mirroringinsert_marked_chain's descent) so nested spans adopt at the deepest shared level. The chain then merges into the same wrapper as usual, emitting one span containing the tags. Atoms not followed by a chain sharing the preceding wrapper's mark keep their legacy sibling placement (unmarked HTML, atoms after a finished span, and the single-run[<b>x</b>](/y)form are unchanged). The helper's atom predicate is the generalization point for the sibling image-atom case (#1407).Tests
New regression tests in
web::markdown:test_marks_spanning_inline_html_roundtrip— link/sup, emphasis, strong, strikethrough spans and consecutive-atom cases round-trip byte-identically with no .test_marks_spanning_inline_html_pm_to_md— save direction alone from hand-built PM.test_inline_html_outside_marks_stays_outside— controls: unmarked atoms and post-span atoms keep placement; single-run form re-parses to the identical PM structure.Verified on the laptop worktree:
cargo test --offline --features web --lib web::markdown— 88 passed (the two spanning tests failed with the exact issue output before the fix);rustfmt --checkclean.Queue task 1481 (repo-health-code-pilot).
Need help on this PR? Tag
@codesmith-botwith what you need.